from dataclasses import dataclass
from typing import Tuple, List


@dataclass
class VideoConfig:
    """视频相关配置"""
    size: Tuple[int, int] = (720, 1280)
    default_fps: int = 24
    segment_fps: int = 12
    

@dataclass
class SubtitleConfig:
    """字幕相关配置"""
    max_chars_per_line: int = 30
    max_lines: int = 2
    min_duration: float = 1.0
    max_duration: float = 5.0
    font_size: int = 11
    stroke_width: int = 3
    margin_bottom: int = 20
    margin_horizontal: int = 20
    embed_to_video: bool =  False
    hardcode_to_video: bool = True
    
    @property
    def max_chars_per_segment(self) -> int:
        return self.max_chars_per_line * self.max_lines


@dataclass
class LLMConfig:
    """LLM API相关配置"""
    base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
    model: str = "kimi-k2-250711"
    temperature: float = 0.7
    max_tokens: int = 1024
    system_prompt: str = """<role>戏剧化图片提示词生成专家</role>

<instruction>
  根据用户提供的故事片段，生成具有强烈戏剧张力的图片生成提示词，重点突出人物间的情感互动和冲突关系。
</instruction>

<guidelines>
  - 必须使用近景(close-up)或中景(medium shot)构图，严格避免远景和空镜头
  - 突出人物之间的情感交流、对立或互动关系
  - 增强戏剧化效果，通过表情、肢体语言、光影等元素营造张力
  - 根据故事情节选择最具冲突性或情感高潮的瞬间
  - 使用富有表现力的视觉语言，如对比强烈的光影、紧张的构图
  - 确保人物在画面中占据主导地位，避免背景抢夺注意力
  - 描述具体的情感状态和微表情，增强戏剧感染力
  - 必须是日本吉卜力漫画风格，不要出现其他风格
</guidelines>

<workflow>
  1. 分析故事片段，识别关键人物和核心冲突点
  2. 确定最具戏剧张力的场景瞬间
  3. 选择合适的镜头角度(近景或中景)突出人物互动
  4. 描述人物表情、姿态和情感状态
  5. 添加光影、色彩等视觉元素增强戏剧效果
  6. 构建完整的图片生成提示词
</workflow>

<output_format>
  - 直接提供完整的英文图片生成prompt
  - 开头明确镜头类型(close-up shot/medium shot)
  - 详细描述人物表情、动作和情感状态
  - 包含光影、构图等戏剧化视觉元素
  - 结尾强调整体戏剧氛围和情感张力
</output_format>

<examples>
  <example>
    <user_query>
      "李明握紧拳头，眼中满含怒火地看着背叛了他的好友张伟。张伟低着头，不敢直视李明的眼睛，手中紧紧攥着那份合同。"
    </user_query>
    <assistant_response>
      日本吉卜力漫画风格,Close-up shot of two men in intense confrontation, one man (angry) with clenched fists and blazing eyes staring directly at camera, his face flushed with rage and betrayal, another man (guilty) looking down shamefully, avoiding eye contact, clutching a contract in his trembling hands, dramatic side lighting creating strong shadows across their faces, high contrast lighting emphasizing the emotional tension, shallow depth of field focusing on their expressions, cinematic drama, raw emotion, psychological intensity, betrayal and guilt written on their faces
    </assistant_response>
  </example>
</examples>"""


@dataclass
class ImageGenConfig:
    """图片生成API相关配置"""
    base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
    model: str = "doubao-seedream-3-0-t2i-250415"
    size: str = "720x1280"
    response_format: str = "url"


@dataclass
class TTSConfig:
    """TTS API相关配置"""
    api_url: str = "http://47.90.179.219:8501/tts_url"
    default_voice_type: str = "英文_男声_磁性硬朗"
    voice_mapping: dict = None
    
    def __post_init__(self):
        if self.voice_mapping is None:
            self.voice_mapping = {
                "英文_男声_磁性硬朗": "/app/audio_prompts/磁性硬朗-男声.MP3",
                "中文_男声_张震": "/app/audio_prompts/张震-男-旁白.wav"
            }


@dataclass
class ProcessingConfig:
    """处理相关配置"""
    max_concurrent_workers: int = 20
    animation_effects: List[str] = None
    
    def __post_init__(self):
        if self.animation_effects is None:
            # self.animation_effects = ["ken_burns", "zoom_in", "zoom_out", "slide_left", "slide_right"]
            self.animation_effects = ["zoom_in", "zoom_out"]



@dataclass
class AppConfig:
    """应用全局配置"""
    video: VideoConfig = None
    subtitle: SubtitleConfig = None
    processing: ProcessingConfig = None
    llm: LLMConfig = None
    image_gen: ImageGenConfig = None
    tts: TTSConfig = None
    
    def __post_init__(self):
        if self.video is None:
            self.video = VideoConfig()
        if self.subtitle is None:
            self.subtitle = SubtitleConfig()
        if self.processing is None:
            self.processing = ProcessingConfig()
        if self.llm is None:
            self.llm = LLMConfig()
        if self.image_gen is None:
            self.image_gen = ImageGenConfig()
        if self.tts is None:
            self.tts = TTSConfig()


# 全局配置实例
config = AppConfig()